# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=kubeshark
pkgver=52.0.0
pkgrel=0
pkgdesc="API traffic viewer for Kubernetes"
url="https://kubeshark.co/"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/kubeshark/kubeshark/archive/refs/tags/v$pkgver.tar.gz"

export CGO_ENABLED=0
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

# The command checks for update on every run
export KUBESHARK_DISABLE_VERSION_CHECK=true

build() {
	local _goldflags="
	-X github.com/kubeshark/kubeshark/misc.GitCommitHash=AlpineLinux
	-X github.com/kubeshark/kubeshark/misc.Branch=main
	-X github.com/kubeshark/kubeshark/misc.BuildTimestamp=$(date -u "+%s" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	-X github.com/kubeshark/kubeshark/misc.Platform=linux_$(go env GOARCH)
	-X github.com/kubeshark/kubeshark/misc.Ver=$pkgver
	"
	go build -v -o bin/$pkgname -ldflags "$_goldflags" kubeshark.go

	for shell in bash fish zsh; do
		./bin/$pkgname completion $shell > $pkgname.$shell
	done
}

check() {
	go test ./...
}

package() {
	install -Dm755 bin/$pkgname -t "$pkgdir"/usr/bin/

	install -Dm644 $pkgname.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 $pkgname.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
0c4395000866bf857d5bd6087191ad0560d71210e0e54a541507b58af002dd9b3079999f118412411e9c6643665afd618436ea8f6e15b34f36e8bfd7580e2eb3  kubeshark-52.0.0.tar.gz
"
